<?php /* PROJECTS $Id: do_project_aed.php,v 1.11.10.4 2006/07/25 20:24:13 merlinyoda Exp $ */
$obj = new CProject();
$project_id = intval( dPgetParam( $_GET, 'project_id', 0 ) );
$obj->load($project_id);
$reasons = $obj->canComplete();
if($reasons != NULL) {
	$AppUI->setMsg( '<p/>'.$reasons, UI_MSG_ERROR );
	$AppUI->redirect("m=projects&a=view&tab=4&project_id=$project_id");
	exit;
}

$completed_date = dPgetParam( $_GET, 'completed_date', 0 );
$obj->project_actual_end_date = substr($completed_date, 0, 4) . '-'.substr($completed_date, 4, 2) . '-'.substr($completed_date, 6, 2) . ' 00:00:00';

//$obj->project_status = 5; // complete, view sysval
require_once(DP_BASE_DIR."/modules/masterdata/mdstatus.class.php");
$complete_status = new CMDStatus();
$project_completed = dPgetSysVal( 'ProjectCompleted' );
$complete_status->loadByCode($project_completed[0]);

$obj->project_rstatus = $complete_status->status_id;
if (($msg = $obj->store())) {
	$AppUI->setMsg( $msg, UI_MSG_ERROR );
	$AppUI->redirect();
	exit;
}

$sql = "update tasks set task_is_complete = 1 where task_project = $project_id";
db_exec($sql);

$AppUI->setMsg( "Project is Completed", UI_MSG_OK, true );
$AppUI->redirect();
?>
